home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 April: Mac OS SDK / Dev.CD Apr 00 SDK1.toast / Development Kits / Mac OS / AppleShare IP 6.3 SDK / ASIP Server Controls⁄Events / Libraries / SyncServerDispatch.c
Encoding:
C/C++ Source or Header  |  1999-11-01  |  4.4 KB  |  144 lines  |  [TEXT/MPS ]

  1. /*
  2. **    Apple Macintosh Developer Technical Support
  3. **
  4. **    Glue to call ServerDispatch from a PowerPC application
  5. **
  6. **    by Jim Luther, Apple Developer Technical Support
  7. **  modified for ASIP 6.0 SDK by Erik Sea
  8. **
  9. **    File:        SyncServerDispatch.c
  10. **
  11. **    Copyright © 1995,1998 Apple Computer, Inc.
  12. **    All rights reserved.
  13. **
  14. **    You may incorporate this sample code into your applications without
  15. **    restriction, though the sample code has been provided "AS IS" and the
  16. **    responsibility for its operation is 100% yours.  However, what you are
  17. **    not permitted to do is to redistribute the source as "DSC Sample Code"
  18. **    after having made changes. If you're going to re-distribute the source,
  19. **    we require that you make it clear in the source that the code was
  20. **    descended from Apple Sample Code, but that you've made changes.
  21. */
  22.  
  23. #include <Types.h>
  24. #include <MixedMode.h>
  25. #include <Errors.h>
  26. #include <Traps.h>
  27.  
  28. #include "AppleShareFileServerControl.h"
  29.  
  30. #ifndef _ServerDispatch
  31. #define    _ServerDispatch        0xa094
  32. #endif
  33.  
  34. /*
  35. **    The function calling convention ServerDispatchProc
  36. */
  37. typedef    pascal OSErr (*ServerDispatchProcPtr)(SInt32 dZero, SCParamBlockRec* thePB);
  38.  
  39. typedef UniversalProcPtr ServerDispatchProcUPP;
  40.  
  41. /*
  42. **    Procedure information for ServerDispatchProc function
  43. */
  44. enum
  45. {
  46.     uppServerDispatchProcInfo = kRegisterBased
  47.          | REGISTER_ROUTINE_PARAMETER(1, kRegisterD1, SIZE_CODE(sizeof(long)))
  48.          | REGISTER_ROUTINE_PARAMETER(2, kRegisterD0, SIZE_CODE(sizeof(long)))
  49.          | REGISTER_ROUTINE_PARAMETER(3, kRegisterA0, SIZE_CODE(sizeof(SCParamBlockRec*)))
  50. };
  51.  
  52. /*
  53. **    The CallServerDispatchProc macro calls ServerDispatch
  54. **    using uppServerDispatchProcInfo defined above.
  55. **
  56. **    Notes:
  57. **        ServerDispatch expects register D0 to always be 0 on input, so the
  58. **        dZero parameter (the first parameter) is always 0.
  59. **
  60. **        Not all versions of Macintosh File Sharing return a result in
  61. **        register D0, so we don't bother to get the value in D0. Instead, the
  62. **        SyncServerDispatch glue code (below) returns the result from the
  63. **        parameter block's ioResult field.
  64. */
  65. #define CallServerDispatchProc(userRoutine, thePB)        \
  66.         CallOSTrapUniversalProc((UniversalProcPtr)(userRoutine), uppServerDispatchProcInfo, _ServerDispatch, 0, (thePB))
  67.  
  68. /*****************************************************************************/
  69.  
  70. /*
  71. **    A concise version of TrapAvailable function.
  72. **    (another effort in the quest for smaller, faster code)
  73. */
  74. static    Boolean    TrapAvailable(short theTrap)
  75. {
  76.     TrapType tType;
  77.     short     numToolboxTraps;
  78.     
  79.     /* Get the trap type */
  80.     if ( (theTrap & 0x0800) > 0 )
  81.         tType = ToolTrap;
  82.     else
  83.         tType = OSTrap;
  84.     
  85.     /* If theTrap is ToolTrap, see if it is in the trap table */
  86.     if ( tType == ToolTrap )
  87.     {
  88.         /* Get the number of toolbox traps */
  89.         if ( NGetTrapAddress(_InitGraf, ToolTrap) == NGetTrapAddress(0xAA6E, ToolTrap) )
  90.             numToolboxTraps = 0x200;
  91.         else
  92.             numToolboxTraps = 0x400;
  93.         
  94.         /* Is theTrap in the trap table? */
  95.         if ( (theTrap & 0x07ff) >= numToolboxTraps )
  96.             theTrap = _Unimplemented;    /* No, make it _Unimplemented */
  97.     }
  98.     
  99.     /* Trap is available if it doesn't equal _Unimplemented */
  100.     return ( NGetTrapAddress(theTrap, tType) != NGetTrapAddress(_Unimplemented, ToolTrap) );
  101. }
  102.  
  103. /*****************************************************************************/
  104.  
  105. /*
  106. **    SyncServerDispatch is the glue code to call the ServerDispatch trap
  107. **    from PowerPC code.
  108. */
  109. pascal OSErr ServerDispatchSync(SCParamBlockRec* PBPtr)
  110. {
  111.     /*
  112.     **    Keep the address of ServerDispatch in a static so we don't
  113.     **    have to check for ServerDispatch and get its address
  114.     **    every time SyncServerDispatch is called.
  115.     */
  116.     static ServerDispatchProcUPP serverDispatchAddress = NULL;
  117.     
  118.     /* If serverDispatchAddress is uninitialized, try to initialize it */
  119.     if ( serverDispatchAddress == NULL )
  120.     {
  121.         /* Make sure ServerDispatch is available (just in case someone didn't check for it first) */
  122.         if ( TrapAvailable(_ServerDispatch) )
  123.         {
  124.             /* Get the address of ServerDispatch */
  125.             serverDispatchAddress = (ServerDispatchProcUPP)NGetTrapAddress(_ServerDispatch, OSTrap);
  126.         }
  127.     }
  128.     
  129.     /* If serverDispatchAddress was initialized */ 
  130.     if ( serverDispatchAddress != NULL )
  131.     {
  132.         /* Call ServerDispatch and return the result from ioResult */
  133.         (void) CallServerDispatchProc(serverDispatchAddress, PBPtr);
  134.         return ( PBPtr->startParam.ioResult );
  135.     }
  136.     else
  137.     {
  138.         /* Return an error to indicate ServerDispatch wasn't available */
  139.         return ( paramErr );
  140.     }
  141. }
  142.  
  143. /*****************************************************************************/
  144.